package com.piece.core.log.config;

import com.piece.core.framework.properties.ApplicationProperties;
import com.piece.core.log.aspect.AuditLogAspect;
import com.piece.core.log.client.LogFactory;
import com.piece.core.log.properties.LogProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;

@Configuration
@ImportAutoConfiguration(LogProperties.class)
public class AuditLogAutoConfiguration {

    @Resource
    private ApplicationProperties applicationProperties;

    @Resource
    private LogProperties logProperties;

    @Autowired
    private ApplicationContext applicationContext;

    @Bean
    public LogFactory logFactory() {
        return new LogFactory(applicationContext, logProperties);
    }

    @Bean
    public AuditLogAspect auditLogAspect() {
        return new AuditLogAspect(applicationProperties, logFactory());
    }
}
